package com.bluesky.common.response;

import com.bluesky.common.error.ErrorEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

@Data
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public  Result(ErrorEnum errorEnum, T data) {
        this.code = errorEnum.getCode();
        this.msg = errorEnum.getMessage();
        this.data=data;
    }

    @JsonIgnore
    public boolean getSuccess() {
        return this.code.equals(ErrorEnum.SUCCESS.getCode());
    }
    private Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> Result(ErrorEnum errorEnum, T data) {
        return new Result<>(errorEnum, data);
    }
    public static <T> Result<T> Result(String code, String msg, T data) {
        return new Result<>(code,msg,data);
    }
}
